package com.laxcen.intelligenttoy.BLE;

import android.app.ProgressDialog;
import android.content.Context;

/**
 * 开门进度条单例,防止创建多个对象，有时候关不掉
 */
public class OpenBleProgreessDialog {

    public static ProgressDialog dialog;

    public OpenBleProgreessDialog() {
    }

    public static ProgressDialog getInstance(Context context){
        //双重锁模式，确保单例创建
        if(dialog == null){
            synchronized (OpenBleProgreessDialog.class){
                if(dialog == null){
                    dialog = new ProgressDialog(context);
                    dialog.setCancelable(false);
                }
            }
        }
        return dialog;
    }


    public static void dismiss(){
        if(dialog != null && dialog.isShowing()){
            dialog.dismiss();
        }
    }


    public static void show(Context context, String title){
        getInstance(context).setTitle(title);
        dialog.show();
    }

    public static void destroy(){
        if(dialog != null){
            dialog.dismiss();
            dialog = null;
        }
    }

}
